home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu11 / pcbugb.arc / TALKSCI.ASC < prev    next >
Text File  |  1991-08-14  |  8KB  |  216 lines

  1. *************************** TALKSCI.ASC 14/8/91 **************************
  2. *   Motorola Copyright 1988,1991                                         *
  3. *   MCU resident, Interrupt driven Communication routines for 68HC11     *
  4. *   monitor. Provides low level memory and stack read/write operations.  *
  5. *                                                                        *
  6. *   This talker DOES NOT use XIRQ                                        *
  7. *   -----------------------------                                        *
  8. *                                                                        *
  9. * N.B. TALKSCI.ASC is a general purpose talker. It is intended to be     *
  10. *      placed in the MCU memory map at $6000 but this can be changed by  *
  11. *      the user to any suitable address. The talker is for general debug *
  12. *      and can be used in any mode as long as the vectors are correctly  *
  13. *      initialised. It is therefore useful for normal modes. The SCI is  *
  14. *      used for communications - use TALKACIA when an external ACIA is   *
  15. *      to be used. TALKSCI assumes that the interrupt vectors are        *
  16. *      pointing to RAM in the same way as the boostrap ROM.              *
  17. *      IMPORTANT : If you change the running address of this program     *
  18. *      then you MUST also change the TALKSCI.MAP file so that the two    *
  19. *      match.                                                            *
  20. *                                                                        *
  21. *      When PCBUG11 is executed with option TALKSCI, a 10mS break is     *
  22. *      output to the 68HC11's SCI, prior to establishing communication.  *
  23. *
  24. * CONSTANTS
  25. TALKBASE  equ $6000
  26. STACK     equ $003F       User may alter this parameter if required
  27. BOOTVECT  equ $00C4       Start of bootstrap vector jump table.
  28. REGBASE   equ $1000       Change if registers are moved
  29. *
  30. JSCI      equ $00C4
  31. JXIRQ     equ $00F1
  32. JSWI      equ $00F4
  33. JILLOP    equ $00F7
  34. JCOP      equ $00FA
  35. JMPEXT    equ $7E         Mnemonic for jump extended instruction
  36. BRKCODE   equ $4A         Break point signal code to host.
  37. BRKACK    equ $4A         Break point acknowledge code from host.
  38. *
  39. * REGISTERS               Change if required for MCU
  40. BAUD      equ $2B
  41. SCCR1     equ $2C
  42. SCCR2     equ $2D
  43. SCSR      equ $2E
  44. SCDR      equ $2F
  45. *
  46. RDRF      equ $20         SCI Masks, change if required
  47. TDRE      equ $80
  48. OR        equ $08
  49. FE        equ $02
  50. *
  51. * PROGRAM
  52.           org TALKBASE
  53. *
  54. * Initialise the SCI and interrupts
  55. *
  56. TLKRSTART EQU *         First dynamically set up Boot vector jump table.
  57.           LDAA #JMPEXT
  58.           LDY #NULLSRV
  59.           LDX #BOOTVECT
  60. SETVECT   EQU *
  61.           STAA ,X
  62.           INX
  63.           STY ,X
  64.           INX
  65.           INX
  66.           CPX #$100
  67.           BNE SETVECT
  68.           LDX #SCISRV
  69.           STX JSCI+1
  70.           LDX #TLKRSTART
  71.           STX JILLOP+1
  72. *
  73. USERSTART EQU *
  74.           LDS #STACK
  75.           LDX #REGBASE
  76.           CLR SCCR1,X
  77.           LDD #$302C
  78.           STAA BAUD,X   Initialise SCI to 9600 baud, no parity, no interrupt
  79.           STAB SCCR2,X  and enable SCI tx & rx.
  80.           LDAA #$40     Enable STOP, and I bit interrupts, disable XIRQ.
  81.           TAP
  82. *
  83. * User may add jump to his own code here or may move the above
  84. * initialisation to the start of his own program. 
  85. * IDLE is the infinite loop which allows the 'STOPPED' mode of PCbug11
  86. *
  87. IDLE      JMP IDLE      Now hang around for SCI interrupt from host.
  88. *
  89. * A RESET from host changes above jump destination to start of user code.
  90. *
  91. SCISRV    EQU *             On detecting interrupt,
  92.           LDAA SCSR+REGBASE assume receiver caused it.
  93.           ANDA #RDRF
  94.           BEQ SCISRV        otherwise program will hang up
  95. *
  96. RXSRV     EQU *             Talker code processes received data.
  97.           LDAA SCDR+REGBASE Read command byte, & echo it as acknowledge
  98.           COMA              Inverted
  99.           BSR OUTSCI        to host.
  100.           BPL INH1      If command bit 7 set, then process inherent command
  101.           BSR INSCI     else read byte count from host into ACCB.(0=256)
  102.           XGDX          Save command and byte count.
  103.           BSR INSCI     Read high address byte
  104.           TBA           into ACCA
  105.           BSR INSCI     then low address byte into ACCB
  106.           XGDX          Restore command in ACCA,count in ACCB,address in X
  107.           CMPA #$FE
  108.           BNE RXSRV1    If command is memory read, then
  109. *
  110. TREADMEM  EQU *         REPEAT
  111.           LDAA ,X             read required address
  112.           BSR OUTSCI          send it to host
  113.           TBA                 (save byte count)
  114.           BSR INSCI           and wait for acknowledge
  115.           TAB                 (restore byte count)
  116.           INX                 Increment address
  117.           DECB                Decrement byte count
  118.           BNE TREADMEM  UNTIL all done
  119.           RTI           and return to idle loop or user code.
  120. *
  121. RXSRV1    EQU *
  122.           CMPA #$BE
  123.           BNE RXSRVEX    If command is memory write then
  124. *
  125.           TBA           move byte count to ACCA
  126. TWRITMEM  EQU *         REPEAT
  127.           BSR INSCI           Read next byte from host into ACCB,
  128.           STAB ,X             and store at required address.
  129.           LDY #$0001          Set up wait loop to allow for external EEPROM
  130. WAITPOLL  DEY                 Y may take on suitable value
  131.           BNE WAITPOLL
  132.           LDAB ,X             Read stored byte and
  133.           STAB SCDR+REGBASE   echo it back to host,
  134.           INX
  135.           DECA                Decrement byte count
  136.           BNE TWRITMEM  UNTIL all done
  137. RXSRVEX   EQU *         and return
  138. NULLSRV   RTI
  139. *
  140. * INSCI gets the received byte form the SCI
  141. *
  142. INSCI     EQU *
  143.           LDAB SCSR+REGBASE   Wait for RDRF=1
  144.           BITB #(FE+OR)       If break detected then
  145.           BNE TLKRSTART       restart talker.
  146.           ANDB #RDRF
  147.           BEQ INSCI
  148.           LDAB SCDR+REGBASE   then read data received from host
  149.           RTS                 and return with data in ACCB
  150. *
  151. * OUTSCI is the subroutine which transmits a byte from the SCI
  152. *
  153. OUTSCI    EQU *               Only register Y modified.
  154.           XGDY                Enter with data to send in ACCA.
  155. OUTSCI1   LDAA SCSR+REGBASE
  156.           BPL OUTSCI1         MS bit is TDRE flag
  157.           XGDY
  158.           STAA SCDR+REGBASE   Important - Updates CCR!
  159.           RTS
  160. *
  161. * Now decide which inherent command was sent
  162. *
  163. INH1      EQU *
  164.           CMPA #$7E     If command is read MCU registers then
  165.           BNE INH2
  166. *
  167. * Command was to read MCU registers
  168. *
  169. INH1A     TSX           Move stack pointer to X
  170.           XGDX          then to ACCD
  171.           BSR OUTSCI    send stack pointer to host (high byte first)
  172.           TBA
  173.           BSR OUTSCI    then low byte
  174.           TSX           Restore X (=stack pointer)
  175.           LDAB #9       then return 9 bytes on stack
  176.           BRA TREADMEM  i.e. CCR,ACCB,ACCA,IXH,IXL,IYH,IYL,PCH,PCL
  177. *
  178. * Command was to write MCU registers
  179. *
  180. INH2      EQU *
  181.           CMPA #$3E     If command is write MCU registers then
  182.           BNE SWISRV1
  183. *
  184.           BSR INSCI     get stack pointer from host (High byte first)
  185.           TBA
  186.           BSR INSCI     get low byte next
  187.           XGDX          Move to X reg
  188.           TXS           and copy to stack pointer
  189.           LDAA #9       Then put next 9 bytes from host on to stack
  190.           BRA TWRITMEM
  191. *
  192. * An SWI interrupt was generated
  193. *
  194. SWISRV    EQU *         Breakpoints generated by host-placed SWI instruction.
  195.           LDAA #BRKCODE Force host to process breakpoints
  196.           BSR OUTSCI    by sending it the break signal
  197. SWIIDLE   CLI
  198.           BRA SWIIDLE   then wait for response from host. (Ibit=0,Xbit=1)
  199. *
  200. SWISRV1   EQU *
  201.           CMPA #BRKACK  If host has acknowledged breakpoint state then
  202.           BNE RXSRVEX
  203.           TSX           move stack pointer to SWI stack frame and
  204.           LDAB #9
  205.           ABX
  206.           TXS
  207.           LDD 7,X       Send user code breakpoint return address to host
  208.           BSR OUTSCI    (high byte first)
  209.           TBA
  210.           BSR OUTSCI    (low byte next)
  211.           LDD #SWIIDLE  force idle loop on return from breakpoint processing
  212.           STD 7,X
  213.           BRA INH1A     but first return all MCU registers to host
  214. *
  215.           END
  216.